package com.ruoyi.oos.web.controller.duty;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oos.duty.domain.Duty;
import com.ruoyi.oos.duty.service.IDutyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮值规则Controller
 * 
 * @author bulang
 * @date 2020-04-27
 */
@Controller
@RequestMapping("/duty/duty")
public class DutyController extends BaseController
{
    private String prefix = "duty/duty";

    @Autowired
    private IDutyService dutyService;

    @RequiresPermissions("duty:duty:view")
    @GetMapping()
    public String duty()
    {
        return prefix + "/duty";
    }

        /**
     * 查询轮值规则列表
     */
    @RequiresPermissions("duty:duty:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Duty duty)
    {
        startPage();
        List<Duty> list = dutyService.selectDutyList(duty);
        return getDataTable(list);
    }
    
    /**
     * 导出轮值规则列表
     */
    @RequiresPermissions("duty:duty:export")
    @Log(title = "轮值规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Duty duty)
    {
        List<Duty> list = dutyService.selectDutyList(duty);
        ExcelUtil<Duty> util = new ExcelUtil<Duty>(Duty.class);
        return util.exportExcel(list, "duty");
    }

    /**
     * 新增轮值规则
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存轮值规则
     */
    @RequiresPermissions("duty:duty:add")
    @Log(title = "轮值规则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Duty duty)
    {
        return toAjax(dutyService.insertDuty(duty));
    }

    /**
     * 修改轮值规则
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Duty duty = dutyService.selectDutyById(id);
        mmap.put("duty", duty);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮值规则
     */
    @RequiresPermissions("duty:duty:edit")
    @Log(title = "轮值规则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Duty duty)
    {
        return toAjax(dutyService.updateDuty(duty));
    }

    /**
     * 删除轮值规则
     */
    @RequiresPermissions("duty:duty:remove")
    @Log(title = "轮值规则", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dutyService.deleteDutyByIds(ids));
    }
}
